package com.str.algorithm;

import java.io.*;

public class Hanoi {

	public static void moveTower(int n, int source, int dest) {
		if (n == 1)
			move(source, dest);
		else {
			int spare = 6 - source - dest;
			moveTower(n - 1, source, spare);
			move(source, dest);
			moveTower(n - 1, spare, dest);
		}
	}

	private static void move(int source, int dest) {
		System.out.println("Move disk from " + source + " to " + dest);
	}

	public static void main(String[] args) throws IOException {
		BufferedReader stdin = new BufferedReader(new InputStreamReader(
				System.in));
		System.out.print("Enter number of disks: ");
		String input = stdin.readLine();
		int ndisks = Integer.parseInt(input);
		moveTower(ndisks, 1, 2);
	}
}
